home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / rpmlog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  8.0 KB  |  285 lines

  1. #ifndef H_RPMLOG
  2. #define H_RPMLOG 1
  3.  
  4. /** \ingroup rpmio
  5.  * \file rpmio/rpmlog.h
  6.  * Yet Another syslog(3) API clone.
  7.  * Used to unify rpmError() and rpmMessage() interfaces in rpm.
  8.  */
  9.  
  10. #include <stdarg.h>
  11.  
  12. /**
  13.  * RPM Log levels.
  14.  * priorities/facilities are encoded into a single 32-bit quantity, where the
  15.  * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
  16.  * (0-big number).  Both the priorities and the facilities map roughly
  17.  * one-to-one to strings in the syslogd(8) source code.  This mapping is
  18.  * included in this file.
  19.  *
  20.  * priorities (these are ordered)
  21.  */
  22. /*@-typeuse@*/
  23. typedef enum rpmlogLvl_e {
  24.     RPMLOG_EMERG    = 0,    /*!< system is unusable */
  25.     RPMLOG_ALERT    = 1,    /*!< action must be taken immediately */
  26.     RPMLOG_CRIT        = 2,    /*!< critical conditions */
  27.     RPMLOG_ERR        = 3,    /*!< error conditions */
  28.     RPMLOG_WARNING    = 4,    /*!< warning conditions */
  29.     RPMLOG_NOTICE    = 5,    /*!< normal but significant condition */
  30.     RPMLOG_INFO        = 6,    /*!< informational */
  31.     RPMLOG_DEBUG    = 7    /*!< debug-level messages */
  32. } rpmlogLvl;
  33. /*@=typeuse@*/
  34.  
  35. #define    RPMLOG_PRIMASK    0x07    /* mask to extract priority part (internal) */
  36.                 /* extract priority */
  37. #define    RPMLOG_PRI(p)    ((p) & RPMLOG_PRIMASK)
  38. #define    RPMLOG_MAKEPRI(fac, pri)    ((((unsigned)(fac)) << 3) | (pri))
  39.  
  40. #ifdef RPMLOG_NAMES
  41. #define    _RPMLOG_NOPRI    0x10    /* the "no priority" priority */
  42.                 /* mark "facility" */
  43. #define    _RPMLOG_MARK    RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
  44. typedef struct _rpmcode {
  45.     const char    *c_name;
  46.     int        c_val;
  47. } RPMCODE;
  48.  
  49. RPMCODE rpmprioritynames[] =
  50.   {
  51.     { "alert",    RPMLOG_ALERT },
  52.     { "crit",    RPMLOG_CRIT },
  53.     { "debug",    RPMLOG_DEBUG },
  54.     { "emerg",    RPMLOG_EMERG },
  55.     { "err",    RPMLOG_ERR },
  56.     { "error",    RPMLOG_ERR },        /* DEPRECATED */
  57.     { "info",    RPMLOG_INFO },
  58.     { "none",    _RPMLOG_NOPRI },    /* INTERNAL */
  59.     { "notice",    RPMLOG_NOTICE },
  60.     { "panic",    RPMLOG_EMERG },        /* DEPRECATED */
  61.     { "warn",    RPMLOG_WARNING },    /* DEPRECATED */
  62.     { "warning",RPMLOG_WARNING },
  63.     { NULL, -1 }
  64.   };
  65. #endif
  66.  
  67. /**
  68.  * facility codes
  69.  */
  70. /*@-enummemuse -typeuse@*/
  71. typedef    enum rpmlogFac_e {
  72.     RPMLOG_KERN        = (0<<3),    /*!< kernel messages */
  73.     RPMLOG_USER        = (1<<3),    /*!< random user-level messages */
  74.     RPMLOG_MAIL        = (2<<3),    /*!< mail system */
  75.     RPMLOG_DAEMON    = (3<<3),    /*!< system daemons */
  76.     RPMLOG_AUTH        = (4<<3),    /*!< security/authorization messages */
  77.     RPMLOG_SYSLOG    = (5<<3),    /*!< messages generated internally by syslogd */
  78.     RPMLOG_LPR        = (6<<3),    /*!< line printer subsystem */
  79.     RPMLOG_NEWS        = (7<<3),    /*!< network news subsystem */
  80.     RPMLOG_UUCP        = (8<<3),    /*!< UUCP subsystem */
  81.     RPMLOG_CRON        = (9<<3),    /*!< clock daemon */
  82.     RPMLOG_AUTHPRIV    = (10<<3),    /*!< security/authorization messages (private) */
  83.     RPMLOG_FTP        = (11<<3),    /*!< ftp daemon */
  84.  
  85.     /* other codes through 15 reserved for system use */
  86.     RPMLOG_LOCAL0    = (16<<3),    /*!< reserved for local use */
  87.     RPMLOG_LOCAL1    = (17<<3),    /*!< reserved for local use */
  88.     RPMLOG_LOCAL2    = (18<<3),    /*!< reserved for local use */
  89.     RPMLOG_LOCAL3    = (19<<3),    /*!< reserved for local use */
  90.     RPMLOG_LOCAL4    = (20<<3),    /*!< reserved for local use */
  91.     RPMLOG_LOCAL5    = (21<<3),    /*!< reserved for local use */
  92.     RPMLOG_LOCAL6    = (22<<3),    /*!< reserved for local use */
  93.     RPMLOG_LOCAL7    = (23<<3),    /*!< reserved for local use */
  94.  
  95. #define    RPMLOG_NFACILITIES 24    /*!< current number of facilities */
  96.     RPMLOG_ERRMSG    = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
  97. } rpmlogFac;
  98. /*@=enummemuse =typeuse@*/
  99.  
  100. #define    RPMLOG_FACMASK    0x03f8    /*!< mask to extract facility part */
  101. #define    RPMLOG_FAC(p)    (((p) & RPMLOG_FACMASK) >> 3)
  102.  
  103.  
  104. #ifdef RPMLOG_NAMES
  105. RPMCODE facilitynames[] =
  106.   {
  107.     { "auth",    RPMLOG_AUTH },
  108.     { "authpriv",RPMLOG_AUTHPRIV },
  109.     { "cron",    RPMLOG_CRON },
  110.     { "daemon",    RPMLOG_DAEMON },
  111.     { "ftp",    RPMLOG_FTP },
  112.     { "kern",    RPMLOG_KERN },
  113.     { "lpr",    RPMLOG_LPR },
  114.     { "mail",    RPMLOG_MAIL },
  115.     { "mark",    _RPMLOG_MARK },        /* INTERNAL */
  116.     { "news",    RPMLOG_NEWS },
  117.     { "security",RPMLOG_AUTH },        /* DEPRECATED */
  118.     { "syslog",    RPMLOG_SYSLOG },
  119.     { "user",    RPMLOG_USER },
  120.     { "uucp",    RPMLOG_UUCP },
  121.     { "local0",    RPMLOG_LOCAL0 },
  122.     { "local1",    RPMLOG_LOCAL1 },
  123.     { "local2",    RPMLOG_LOCAL2 },
  124.     { "local3",    RPMLOG_LOCAL3 },
  125.     { "local4",    RPMLOG_LOCAL4 },
  126.     { "local5",    RPMLOG_LOCAL5 },
  127.     { "local6",    RPMLOG_LOCAL6 },
  128.     { "local7",    RPMLOG_LOCAL7 },
  129.     { NULL, -1 }
  130.   };
  131. #endif
  132.  
  133. /*
  134.  * arguments to setlogmask.
  135.  */
  136. #define    RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))    /*!< mask for one priority */
  137. #define    RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)    /*!< all priorities through pri */
  138.  
  139. /*
  140.  * Option flags for openlog.
  141.  *
  142.  * RPMLOG_ODELAY no longer does anything.
  143.  * RPMLOG_NDELAY is the inverse of what it used to be.
  144.  */
  145. #define    RPMLOG_PID    0x01    /*!< log the pid with each message */
  146. #define    RPMLOG_CONS    0x02    /*!< log on the console if errors in sending */
  147. #define    RPMLOG_ODELAY    0x04    /*!< delay open until first syslog() (default) */
  148. #define    RPMLOG_NDELAY    0x08    /*!< don't delay open */
  149. #define    RPMLOG_NOWAIT    0x10    /*!< don't wait for console forks: DEPRECATED */
  150. #define    RPMLOG_PERROR    0x20    /*!< log to stderr as well */
  151.  
  152. /**
  153.  * @todo Add argument(s), integrate with other types of callbacks.
  154.  */
  155. typedef void (*rpmlogCallback) (void);
  156.  
  157. /**
  158.  */
  159. typedef /*@abstract@*/ struct rpmlogRec_s {
  160.     int        code;
  161. /*@owned@*/ /*@null@*/
  162.     const char * message;
  163. } * rpmlogRec;
  164.  
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168.  
  169. /**
  170.  * Return number of rpmError() ressages.
  171.  * @return        number of messages
  172.  */
  173. int rpmlogGetNrecs(void)    /*@*/;
  174.  
  175. /**
  176.  * Print all rpmError() messages.
  177.  * @param f        file handle (NULL uses stderr)
  178.  */
  179. void rpmlogPrint(/*@null@*/ FILE *f)
  180.     /*@modifies *f @*/;
  181.  
  182. /**
  183.  * Close desriptor used to write to system logger.
  184.  * @todo Implement.
  185.  */
  186. /*@unused@*/
  187. void rpmlogClose (void)
  188.     /*@globals internalState@*/
  189.     /*@modifies internalState @*/;
  190.  
  191. /**
  192.  * Open connection to system logger.
  193.  * @todo Implement.
  194.  */
  195. /*@unused@*/
  196. void rpmlogOpen (const char * ident, int option, int facility)
  197.     /*@globals internalState@*/
  198.     /*@modifies internalState @*/;
  199.  
  200. /**
  201.  * Set the log mask level.
  202.  * @param mask        log mask (0 is no operation)
  203.  * @return        previous log mask
  204.  */
  205. int rpmlogSetMask (int mask)
  206.     /*@globals internalState@*/
  207.     /*@modifies internalState @*/;
  208.  
  209. /**
  210.  * Generate a log message using FMT string and option arguments.
  211.  */
  212. /*@mayexit@*/ /*@printflike@*/ void rpmlog (int code, const char *fmt, ...)
  213.     /*@*/;
  214.  
  215. /*@-exportlocal@*/
  216. /**
  217.  * Return text of last rpmError() message.
  218.  * @return        text of last message
  219.  */
  220. /*@-redecl@*/
  221. /*@observer@*/ /*@null@*/ const char * rpmlogMessage(void)
  222.     /*@*/;
  223. /*@=redecl@*/
  224.  
  225. /**
  226.  * Return error code from last rpmError() message.
  227.  * @deprecated Perl-RPM needs, what's really needed is predictable, non-i18n
  228.  *    encumbered, error text that can be retrieved through rpmlogMessage()
  229.  *    and parsed IMHO.
  230.  * @return        code from last message
  231.  */
  232. int rpmlogCode(void)
  233.     /*@*/;
  234.  
  235. /**
  236.  * Set rpmlog callback function.
  237.  * @param cb        rpmlog callback function
  238.  * @return        previous rpmlog callback function
  239.  */
  240. rpmlogCallback rpmlogSetCallback(rpmlogCallback cb)
  241.     /*@globals internalState@*/
  242.     /*@modifies internalState @*/;
  243.  
  244. /**
  245.  * Set rpmlog file handle.
  246.  * @param fp        rpmlog file handle (NULL uses stdout/stderr)
  247.  * @return        previous rpmlog file handle
  248.  */
  249. /*@null@*/
  250. FILE * rpmlogSetFile(/*@null@*/ FILE * fp)
  251.     /*@globals internalState@*/
  252.     /*@modifies internalState @*/;
  253. /*@=exportlocal@*/
  254.  
  255. /**
  256.  * Set rpmlog callback function.
  257.  * @deprecated gnorpm needs, use rpmlogSetCallback() instead.
  258.  */
  259. extern rpmlogCallback rpmErrorSetCallback(rpmlogCallback cb)
  260.     /*@globals internalState@*/
  261.     /*@modifies internalState @*/;
  262.  
  263. /**
  264.  * Return error code from last rpmError() message.
  265.  * @deprecated Perl-RPM needs, use rpmlogCode() instead.
  266.  * @return        code from last message
  267.  */
  268. extern int rpmErrorCode(void)
  269.     /*@*/;
  270.  
  271. /**
  272.  * Return text of last rpmError() message.
  273.  * @deprecated gnorpm needs, use rpmlogMessage() instead.
  274.  * @return        text of last message
  275.  */
  276. /*@-redecl@*/
  277. /*@observer@*/ /*@null@*/ extern const char * rpmErrorString(void)    /*@*/;
  278. /*@=redecl@*/
  279.  
  280. #ifdef __cplusplus
  281. }
  282. #endif
  283.  
  284. #endif /* H_RPMLOG */
  285.